<template>
  <div>
    <v-header></v-header>
    <div class="wrap">
      <div>
        <img src="./img/orange.png" alt="" />
      </div>
      <van-cell-group inset>
        <van-field
          label="手机号"
          center
          clearable
          placeholder="手机号"
          v-model="phone"
        ></van-field>

        <van-field
          label="密码"
          center
          clearable
          placeholder="请输入密码"
          v-model="password"
          type="password"
        >
          <!-- <template #button>
            <van-button color="#ccc" size="small" type="primary">获取验证码</van-button>
          </template> -->
        </van-field>
      </van-cell-group>
      <button class="btn" @click="btn">登录</button>
      <button class="btn2" @click="$router.replace('/register')">去注册</button>
    </div>
  </div>
</template>

<script>
import { getLogin } from "@/request/api.js";
import { Toast } from "vant";
export default {
  data() {
    return {
      phone: "",
      password: "",
    };
  },
  methods: {
    async btn() {
      let obj = {
        phone: this.phone,
        password: this.password,
      };

      let res = await getLogin(obj);
      console.log("res",res);

      // 判断是否登录成功
      if (res.data.code == 200) {
        // 纯放token
        let user = JSON.stringify(res.data.list);
        console.log(res.data.list);
        // console.log(list);
        localStorage.user = user;
        Toast.success(res.data.msg)
        setTimeout(()=>{
          console.log(this.$router.go(-1),111);
          
            this.$router.push('/index/home')
        },2000)
      }

      // console.log(res);
    },
  },
};
</script>

<style scoped>
input {
  outline: none;
  border: none;
  border-bottom: 1px solid #ccc;
}
.btn {
  outline: none;
  border: none;
  background-color: #ccc;
  color: white;
  margin-top: 0.3rem;
  width: 75vw;
  height: 0.4rem;
  line-height: 0.4rem;
  border-radius: 0.2rem;
  background-color: green;
}
.btn2 {
  margin-top: 0.03rem;
  outline: none;
  border: none;
  background-color: #ccc;
  color: white;
  width: 75vw;
  height: 0.4rem;
  line-height: 0.4rem;
  background-color: tomato;
  border-radius: 0.2rem;
}
.wrap {
  width: 90vw;
  position: absolute;
  top: 35%;
  left: 5vw;
  text-align: center;
  /* border: 1px solid red; */
}
img {
  margin-bottom: 0.6rem;
}
.van-field {
  width: 75vw;
}
</style>